package com.dropTables.TakingNote;

import android.app.TabActivity;
import android.widget.TabHost;
import android.content.res.Resources;
import android.content.Intent;
import android.os.Bundle;


public class NoteEditActivity extends TabActivity {
	public static String title;
	public static String body;
	public static String gen_loc;
	public static String spec_loc;
	public static int hour;
	public static int min;
	public static int day;
	public static int month;
	public static int year;
	public static Long rRowId;
	public static Long rId;
	private static TabHost tabHost;
	private static String tabId;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Resources res = getResources(); // Resource object to get Drawables
        tabHost = getTabHost();  // The activity TabHost
        TabHost.TabSpec spec;  // Resusable TabSpec for each tab
        Intent intent;  // Reusable Intent for each tab
        
        //If there are extras that means that we are editing so set up for this.
        Bundle extras = getIntent().getExtras();
		if (extras != null) 
		{
			title = extras.getString(ReminderDbHelper.KEY_TITLE);
			body = extras.getString(ReminderDbHelper.KEY_BODY);
			gen_loc= extras.getString(ReminderDbHelper.KEY_G_LOC);
			spec_loc = extras.getString(ReminderDbHelper.KEY_S_LOC);
			rRowId = extras.getLong(ReminderDbHelper.KEY_ROWID);
			rId = extras.getLong(ReminderDbHelper.KEY_R_ID);
			hour=extras.getInt("hour");
			min =extras.getInt("min");
			day=extras.getInt("day");
			month = extras.getInt("month");
			year = extras.getInt("year");
		}
		if(extras==null)
		{
			title = "";
			body = "";
			gen_loc= "";
			rRowId = -1L;
			hour = -1;
			rId = -1L;
			spec_loc = "";
		}
		//Text Edit tab setup
        intent = new Intent(this, TextEditActivity.class);
        if(extras != null)
        	intent.putExtras( extras);
        TabHost.TabSpec tabSpec;
        tabSpec = tabHost.newTabSpec("Text Edit");
        spec = tabSpec.setIndicator("Text",res.getDrawable(R.drawable.icon_notepad));
        spec = spec.setContent(intent);
		tabHost.addTab(spec);
		
		//Time edit  tab setup
		intent = new Intent(this, TimeEditActivity.class);
		if(extras != null)
			intent.putExtras( extras);
		tabSpec = tabHost.newTabSpec("Time Edit");
		spec = tabSpec.setIndicator("Time",res.getDrawable(R.drawable.icon_clock));
		spec = spec.setContent(intent);
		tabHost.addTab(spec);
		
		//Location Edit tab setup
		intent = new Intent(this, LocationEditActivity.class);
		if(extras != null)
			intent.putExtras( extras);
		tabSpec = tabHost.newTabSpec("Location Edit");
		spec = tabSpec.setIndicator("Location", res.getDrawable(R.drawable.icon_map));
		spec = spec.setContent(intent);
		tabHost.addTab(spec);
		
		
		tabId = "Text Edit";
        tabHost.setCurrentTab(0);
        tabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener()
        {
        	@Override
        	public void onTabChanged(String tabId) {
        		if(NoteEditActivity.tabId.equals("Text Edit"))
        		{
        			title = TextEditActivity.rTitleText.getText().toString();
    				body = TextEditActivity.rBodyText.getText().toString();
        		}
        		else if(NoteEditActivity.tabId.equals("Location Edit"))
        		{
        			spec_loc = LocationEditActivity.loc_addr_get.getText().toString();
        			gen_loc = LocationEditActivity.rSearchText.getText().toString();
        		}
        		else if(NoteEditActivity.tabId.equals("Time Edit"))
        		{
        			month = TimeEditActivity.dp.getMonth();
					year = TimeEditActivity.dp.getYear();
					day = TimeEditActivity.dp.getDayOfMonth();
					hour = TimeEditActivity.tp.getCurrentHour();
					min = TimeEditActivity.tp.getCurrentMinute();
					System.out.println("Time Edit "+hour);
        		}
        		NoteEditActivity.tabId =tabId;
        	}
        });
    }
}